package com.ctrip.study.algorithm.leetcode;

import org.junit.Test;

import junit.framework.TestCase;

/**
 * Maximum Depth of Binary Tree.
 */
public class CalcMaxDepthTree extends TestCase{

	public class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}
	
	
 	public int maxDepth(TreeNode root) {
 		if(root == null){
 			return 0;
 		}
 		int leftLength = maxDepth(root.left);
 		int ringhtLength = maxDepth(root.right);
 		return leftLength > ringhtLength ? leftLength + 1 : ringhtLength + 1;
 	}

 	
 	@Test
 	public void test(){
 		TreeNode root = new TreeNode(30);
 		TreeNode t1_1 = new TreeNode(9);
 		TreeNode t1_2 = new TreeNode(94);
 		root.left = t1_1;
 		root.right = t1_2;
 		
 		System.out.println(new CalcMaxDepthTree().maxDepth(root));
 	}
 	
}
